package work.xkong.controller;


import io.jsonwebtoken.Claims;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;
import work.xkong.common.ResponseRest;
import work.xkong.mapper.TeacherMapper;
import work.xkong.service.ITeacherService;
import work.xkong.utils.TokenUtils;
import work.xkong.vo.inputvo.TeacherCourseSaveInputVo;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author NuanYang
 * @since 2022-11-21
 */
@RestController
@RequestMapping("/teacher")
public class TeacherController {
    @Autowired
    private ITeacherService teacherService;

    @PutMapping("/saveCourse")
    public ResponseRest saveCourse(HttpServletRequest request, @RequestBody TeacherCourseSaveInputVo inputVo){
        String jwt = request.getHeader("Authorization");
        String teacherId = (String) TokenUtils.getParseToken(jwt).get(Claims.ID);

        inputVo.setId(Integer.parseInt(teacherId));

        return teacherService.saveCourse(inputVo);
    }

}
